﻿
namespace Apache.Cassandra.Client {
    using System;
    using System.Diagnostics;
    using System.Security;
    using System.Threading;

    internal static class ExceptionExtensions {

        static private readonly Type StackOverflowType = typeof(StackOverflowException);
        static private readonly Type OutOfMemoryType = typeof(OutOfMemoryException);
        static private readonly Type ThreadAbortType = typeof(ThreadAbortException);
        static private readonly Type NullReferenceType = typeof(NullReferenceException);
        static private readonly Type AccessViolationType = typeof(AccessViolationException);
        static private readonly Type SecurityType = typeof(SecurityException);

        public static bool IsCatchableType(this Exception e) {
            Debug.Assert(e != null);
            Type type = e.GetType();
 
            return type != StackOverflowType && type != OutOfMemoryType && type != ThreadAbortType && type != NullReferenceType && type != AccessViolationType && !SecurityType.IsAssignableFrom(type);
        }
    }
}
